package estadistica;

public class ChannelOptimizer {


	public static int getTotalChannels(
			Integer totalClients,
			Integer maxClientsTolerance,
			Double lambda,
			Double mu,
			Integer maxChannels) throws Exception {
		
		QueueFunction qf = null;
		double Lc = 0.00;
		
		try {
			qf = new QueueFunction(lambda, mu, maxChannels, totalClients);
			Lc = qf.getLc();
		}
		catch(Exception e) {
			throw new Exception("El sistema no tiene la capacidad para atender los clientes que ingresan.");
		}
		
		if(Lc > maxClientsTolerance)
			throw new Exception("Imposible cumplir restriccion");
		
		int optChannels = maxChannels;
		
		for(int currChannels = maxChannels - 1; Lc < maxClientsTolerance;currChannels--) {
			try {
				qf = new QueueFunction(lambda, mu, currChannels, totalClients);
				Lc = qf.getLc();
				if(Lc <= maxClientsTolerance)
					optChannels = currChannels;
			}
			catch(Exception e) {
				break;
			}
		}
		
		return optChannels;
	}	
}
